<?php
	class Code_export_form_model extends CI_Model {
	    
    var $id;
	var $code;    	
    var $export_form_id;    
	var $active;

    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }

    // load all Storage
    function loadAll($cond = false)
    {
        if($cond)
        {
            $query = $this->db->get_where('code_export_form',array('export_form_id' => $cond));
        }
        else
        {
            $query = $this->db->get('code_export_form');
        }        
        return $query->result();
    }    

    // load all storage [update] v2
    function loadAllV2($cond = false)
    {
        $this->db->select('*');
        $this->db->from('code_export_form');

        if($cond)
        {
            if(!empty($cond['code_export_form']))
                $this->db->where('export_form_id',$cond['code_export_form']);
            if(!empty($cond['order_id']))
                $this->db->where('order_id',$cond['order_id']);
            if(!empty($cond['limit']))
            {
                $this->db->limit($cond['limit']['end'],$cond['limit']['start']);
            }
        }        

        $this->db->order_by('id','desc');        

        $query = $this->db->get();                

        $return_data = array(
                'return'  =>  $query->result(),
                'count'   =>  $this->db->count_all('code_export_form'),
            );

        if(!empty($cond['code_export_form']))
            $return_data['count'] = $this->loadAllV2Count($cond);        
            
        return $return_data;
    }

    // 
    function loadAllV2Count($cond)
    {
        $this->db->select('*');
        $this->db->from('code_export_form');        

        if(!empty($cond))
        {
            if(!empty($cond['code_export_form']) && $cond['code_export_form'] != 'false')
                $this->db->where('export_form_id', $cond['code_export_form']);
        }        
        
        return $this->db->count_all_results();
    } 

    function getEntry($id)
    {
        $query = $this->db->get_where('code_export_form', array('id' => $id));
        return $query->row();
    }    

    function insert($data)
    {
        $this->db->insert('code_export_form', $data);
        return $this->db->insert_id();
    }

    function update($data,$id)
    {
        $this->db->where('id',$id);
        $this->db->update('code_export_form',$data);
    }

}